﻿using System;
using System.IO;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Reflection;
using System.Text;
using ByteSite.Common;
using System.Linq.Expressions;

namespace ByteSite.BLL
{
    /// <summary>
    /// 系统频道表
    /// </summary>
    public partial class site_channel
    {
        private readonly Entitys.sysconfig sysConfig = new BLL.sysconfig().loadConfig();//获得系统配置信息
        private readonly DAL.Data data;

        public site_channel()
        {
            data = new DAL.Data();
        }

        #region 基本方法================================
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int id)
        {
            return data.Exists<Entitys.dt_site_channel>(id);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Entitys.dt_site_channel model)
        {
            try
            {
                data.BeginTran();
                //取得站点对应的导航，如果站点导航不存在则退出新增
                int parent_id = new DAL.sites().GetSiteNavId(Utils.ObjToInt(model.site_id));
                if (parent_id == 0)
                {
                    return 0;
                }
                model.id = data.Insert<Entitys.dt_site_channel>(model);

                //新增扩展字段及创建频道数据表
                List<int> fieldIds = new List<int>();//存储已加截的扩展字段ID集合
                foreach (Entitys.dt_site_channel_field modelt in model.channel_fields)
                {
                    fieldIds.Add(Utils.ObjToInt(modelt.field_id));
                    data.Insert<Entitys.dt_site_channel_field>(new Entitys.dt_site_channel_field() { channel_id = model.id, field_id = modelt.field_id });
                }

                //创建频道数据表
                string table = sysConfig.sysdatabaseprefix + DTKeys.TABLE_CHANNEL_ARTICLE + model.name;
                 data.CreateTable(table, typeof(Entitys.article));

                if (fieldIds.Count > 0)
                {
                    //查询扩展字段表
                    List<Entitys.dt_article_attribute_field> fields = data.List<Entitys.dt_article_attribute_field>(x => fieldIds.Contains(x.id), x => x.sort_id);

                    foreach (Entitys.dt_article_attribute_field field in fields)
                    {
                        SqlSugar.DbColumnInfo dbColumn = new SqlSugar.DbColumnInfo();
                        dbColumn.DbColumnName = field.name;
                        if (field.control_type == "single-text")
                        {
                            dbColumn.DataType = data.GetDbTypeName(typeof(System.String).Name);
                            dbColumn.PropertyType = typeof(System.String);
                            dbColumn.Length = Utils.ObjToInt(field.data_length);
                            dbColumn.ColumnDescription = field.name;
                            dbColumn.DefaultValue = field.default_value;
                            dbColumn.IsNullable = true;
                        }
                        else if (field.control_type == "number" && field.data_place > 0)
                        {
                            dbColumn.DataType = data.GetDbTypeName(typeof(System.Decimal).Name);
                            dbColumn.PropertyType = typeof(System.Decimal);
                            dbColumn.Length = Utils.ObjToInt(9);
                            dbColumn.DecimalDigits = Utils.ObjToInt(field.data_place);
                            dbColumn.ColumnDescription = field.name;
                            dbColumn.DefaultValue = field.default_value;
                            dbColumn.IsNullable = true;
                        }
                        else if (field.control_type == "number" && field.data_place == 0)
                        {
                            dbColumn.DataType = data.GetDbTypeName(typeof(System.Int32).Name);
                            dbColumn.PropertyType = typeof(System.Int32);
                            dbColumn.ColumnDescription = field.name;
                            dbColumn.DefaultValue = field.default_value;
                            dbColumn.IsNullable = true;
                        }
                        else if (field.control_type == "datetime")
                        {
                            dbColumn.DataType = data.GetDbTypeName(typeof(System.DateTime).Name);
                            dbColumn.PropertyType = typeof(System.DateTime);
                            dbColumn.ColumnDescription = field.name;
                            dbColumn.DefaultValue = field.default_value;
                            dbColumn.IsNullable = true;
                        }
                        else if (field.control_type == "multi-text")
                        {
                            dbColumn.DataType = data.GetDbTypeName(typeof(System.String).Name);
                            dbColumn.PropertyType = typeof(System.String);
                            dbColumn.Length = Utils.ObjToInt(field.data_length);
                            dbColumn.ColumnDescription = field.name;
                            dbColumn.DefaultValue = field.default_value;
                            dbColumn.IsNullable = true;
                        }
                        else if (field.control_type == "editor")
                        {
                            dbColumn.DataType = data.GetDbTypeName(typeof(System.String).Name);
                            dbColumn.PropertyType = typeof(System.String);
                            dbColumn.Length = int.MaxValue;
                            dbColumn.ColumnDescription = field.name;
                            dbColumn.DefaultValue = field.default_value;
                            dbColumn.IsNullable = true;
                        }
                        else if (field.control_type == "images" || field.control_type == "video")
                        {
                            dbColumn.DataType = data.GetDbTypeName(typeof(System.String).Name);
                            dbColumn.PropertyType = typeof(System.String);
                            dbColumn.Length = 255;
                            dbColumn.ColumnDescription = field.name;
                            dbColumn.DefaultValue = field.default_value;
                            dbColumn.IsNullable = true;
                        }
                        else if (field.control_type == "checkbox")
                        {
                            dbColumn.DataType = data.GetDbTypeName(typeof(System.Int32).Name);
                            dbColumn.PropertyType = typeof(System.Int32);
                            dbColumn.ColumnDescription = field.name;
                            dbColumn.DefaultValue = field.default_value;
                            dbColumn.IsNullable = true;
                        }
                        else if (field.control_type == "multi-radio" && field.data_type == "int")
                        {
                            dbColumn.DataType = data.GetDbTypeName(typeof(System.Int32).Name);
                            dbColumn.PropertyType = typeof(System.Int32);
                            dbColumn.ColumnDescription = field.name;
                            dbColumn.DefaultValue = field.default_value;
                            dbColumn.IsNullable = true;
                        }
                        else if (field.control_type == "multi-radio" && field.data_type.StartsWith("nvarchar"))
                        {
                            dbColumn.DataType = data.GetDbTypeName(typeof(System.String).Name);
                            dbColumn.PropertyType = typeof(System.String);
                            dbColumn.Length = Utils.ObjToInt(field.data_length);
                            dbColumn.ColumnDescription = field.name;
                            dbColumn.DefaultValue = field.default_value;
                            dbColumn.IsNullable = true;
                        }
                        else if (field.control_type == "multi-checkbox")
                        {
                            dbColumn.DataType = data.GetDbTypeName(typeof(System.String).Name);
                            dbColumn.PropertyType = typeof(System.String);
                            dbColumn.Length = Utils.ObjToInt(field.data_length);
                            dbColumn.ColumnDescription = field.name;
                            dbColumn.DefaultValue = field.default_value;
                            dbColumn.IsNullable = true;
                        }
                        else
                        {
                            dbColumn.DataType = data.GetDbTypeName(typeof(System.String).Name);
                            dbColumn.PropertyType = typeof(System.String);
                            dbColumn.Length = 255;
                            dbColumn.ColumnDescription = field.name;
                            dbColumn.DefaultValue = field.default_value;
                            dbColumn.IsNullable = true;
                        }
                        //dbColumn.DecimalDigits
                        data.AddColumn(table, dbColumn);
                    }
                }

                #region 写入导航数据===============
                new DAL.navigation().Add(parent_id, "channel_" + model.name, model.title, "", Utils.ObjToInt(model.sort_id), model.id, "Show");
                int newNavId = new DAL.navigation().Add(parent_id, "channel_" + model.name, model.title, "", Utils.ObjToInt(model.sort_id), model.id, "Show");
                new DAL.navigation().Add( newNavId, "channel_" + model.name + "_list", "内容管理", "article/article_list.aspx", 99, model.id, "Show,View,Add,Edit,Delete,Audit");
                new DAL.navigation().Add( newNavId, "channel_" + model.name + "_category", "栏目类别", "article/category_list.aspx", 100, model.id, "Show,View,Add,Edit,Delete");
                //开启规格新增菜单
                if (model.is_spec > 0)
                {
                    new DAL.navigation().Add( newNavId, "channel_" + model.name + "_spec", "规格管理", "article/spec_list.aspx", 102, model.id, "Show,View,Add,Edit,Delete");
                }
                //开启评论则新增菜单
                if (model.is_comment > 0)
                {
                    new DAL.navigation().Add(newNavId, "channel_" + model.name + "_comment", "评论管理", "article/comment_list.aspx", 103, model.id, "Show,View,Delete,Reply");
                }
                #endregion

                data.CommitTran();
            }
            catch (Exception ex)
            {
                data.RollbackTran();
                return 0;
            }
            return model.id;
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Entitys.dt_site_channel model)
        {
            int siteNavParentId = new DAL.sites().GetSiteNavId(Utils.ObjToInt(model.site_id));//取得站点对应的导航ID
           
            Entitys.dt_site_channel prevModel = GetModel(model.id);

            try
            {
                data.BeginTran();
                string table = sysConfig.sysdatabaseprefix + DTKeys.TABLE_CHANNEL_ARTICLE + prevModel.name;
                data.Update<Entitys.dt_site_channel>(model);

                //删除已移除的扩展字段
                if (prevModel.channel_fields != null)
                {
                    List<int> fieldIds = new List<int>();
                    foreach (Entitys.dt_site_channel_field modelt in prevModel.channel_fields)
                    {
                        if (model.channel_fields.Find(p => p.field_id == modelt.field_id) == null)
                        {
                            fieldIds.Add(Utils.ObjToInt(modelt.field_id));
                            data.Delete<Entitys.dt_site_channel_field>(x => x.channel_id == model.id && x.field_id == modelt.field_id);
                        }
                    }

                    //删除频道数据表列
                    List<Entitys.dt_article_attribute_field> fieldList = data.List<Entitys.dt_article_attribute_field>(x => fieldIds.Contains(x.id));
                    foreach (Entitys.dt_article_attribute_field f in fieldList)
                    {
                        data.DropColumn(table, f.name);
                    }
                }
                if (model.channel_fields != null)
                {
                    List<int> newFieldIds = new List<int>();
                    foreach (Entitys.dt_site_channel_field modelt in model.channel_fields)
                    {
                        Entitys.dt_site_channel_field fieldModel = null;
                        if (prevModel.channel_fields != null)
                        {
                            fieldModel = prevModel.channel_fields.Find(p => p.field_id == modelt.field_id);
                        }
                        //如不存在字段则添加
                        if (fieldModel == null)
                        {
                            newFieldIds.Add(Utils.ObjToInt(modelt.field_id));
                            data.Insert<Entitys.dt_site_channel_field>(new Entitys.dt_site_channel_field() { channel_id = modelt.channel_id, field_id = modelt.field_id });
                        }
                    }
                    if (newFieldIds.Count > 0)
                    {
                        List<Entitys.dt_article_attribute_field> list = data.List<Entitys.dt_article_attribute_field>(x => newFieldIds.Contains(x.id), x => x.sort_id);
                        foreach (Entitys.dt_article_attribute_field field in list)
                        {
                            SqlSugar.DbColumnInfo dbColumn = new SqlSugar.DbColumnInfo();
                            dbColumn.DbColumnName = field.name;
                            if (field.control_type == "single-text")
                            {
                                dbColumn.DataType = data.GetDbTypeName(typeof(System.String).Name);
                                dbColumn.PropertyType = typeof(System.String);
                                dbColumn.Length = Utils.ObjToInt(field.data_length);
                                dbColumn.ColumnDescription = field.name;
                                dbColumn.DefaultValue = field.default_value;
                                dbColumn.IsNullable = true;
                            }
                            else if (field.control_type == "number" && field.data_place > 0)
                            {
                                dbColumn.DataType = data.GetDbTypeName(typeof(System.Decimal).Name);
                                dbColumn.PropertyType = typeof(System.Decimal);
                                dbColumn.Length = Utils.ObjToInt(9);
                                dbColumn.DecimalDigits = Utils.ObjToInt(field.data_place);
                                dbColumn.ColumnDescription = field.name;
                                dbColumn.DefaultValue = field.default_value;
                                dbColumn.IsNullable = true;
                            }
                            else if (field.control_type == "number" && field.data_place == 0)
                            {
                                dbColumn.DataType = data.GetDbTypeName(typeof(System.Int32).Name);
                                dbColumn.PropertyType = typeof(System.Int32);
                                dbColumn.ColumnDescription = field.name;
                                dbColumn.DefaultValue = field.default_value;
                                dbColumn.IsNullable = true;
                            }
                            else if (field.control_type == "datetime")
                            {
                                dbColumn.DataType = data.GetDbTypeName(typeof(System.DateTime).Name);
                                dbColumn.PropertyType = typeof(System.DateTime);
                                dbColumn.ColumnDescription = field.name;
                                dbColumn.DefaultValue = field.default_value;
                                dbColumn.IsNullable = true;
                            }
                            else if (field.control_type == "multi-text")
                            {
                                dbColumn.DataType = data.GetDbTypeName(typeof(System.String).Name);
                                dbColumn.PropertyType = typeof(System.String);
                                dbColumn.Length = Utils.ObjToInt(field.data_length);
                                dbColumn.ColumnDescription = field.name;
                                dbColumn.DefaultValue = field.default_value;
                                dbColumn.IsNullable = true;
                            }
                            else if (field.control_type == "editor")
                            {
                                dbColumn.DataType = data.GetDbTypeName(typeof(System.String).Name);
                                dbColumn.PropertyType = typeof(System.String);
                                dbColumn.Length = int.MaxValue;
                                dbColumn.ColumnDescription = field.name;
                                dbColumn.DefaultValue = field.default_value;
                                dbColumn.IsNullable = true;
                            }
                            else if (field.control_type == "images" || field.control_type == "video")
                            {
                                dbColumn.DataType = data.GetDbTypeName(typeof(System.String).Name);
                                dbColumn.PropertyType = typeof(System.String);
                                dbColumn.Length = 255;
                                dbColumn.ColumnDescription = field.name;
                                dbColumn.DefaultValue = field.default_value;
                                dbColumn.IsNullable = true;
                            }
                            else if (field.control_type == "checkbox")
                            {
                                dbColumn.DataType = data.GetDbTypeName(typeof(System.Int32).Name);
                                dbColumn.PropertyType = typeof(System.Int32);
                                dbColumn.ColumnDescription = field.name;
                                dbColumn.DefaultValue = field.default_value;
                                dbColumn.IsNullable = true;
                            }
                            else if (field.control_type == "multi-radio" && field.data_type == "int")
                            {
                                dbColumn.DataType = data.GetDbTypeName(typeof(System.Int32).Name);
                                dbColumn.PropertyType = typeof(System.Int32);
                                dbColumn.ColumnDescription = field.name;
                                dbColumn.DefaultValue = field.default_value;
                                dbColumn.IsNullable = true;
                            }
                            else if (field.control_type == "multi-radio" && field.data_type.StartsWith("nvarchar"))
                            {
                                dbColumn.DataType = data.GetDbTypeName(typeof(System.String).Name);
                                dbColumn.PropertyType = typeof(System.String);
                                dbColumn.Length = Utils.ObjToInt(field.data_length);
                                dbColumn.ColumnDescription = field.name;
                                dbColumn.DefaultValue = field.default_value;
                                dbColumn.IsNullable = true;
                            }
                            else if (field.control_type == "multi-checkbox")
                            {
                                dbColumn.DataType = data.GetDbTypeName(typeof(System.String).Name);
                                dbColumn.PropertyType = typeof(System.String);
                                dbColumn.Length = Utils.ObjToInt(field.data_length);
                                dbColumn.ColumnDescription = field.name;
                                dbColumn.DefaultValue = field.default_value;
                                dbColumn.IsNullable = true;
                            }
                            else
                            {
                                dbColumn.DataType = data.GetDbTypeName(typeof(System.String).Name);
                                dbColumn.PropertyType = typeof(System.String);
                                dbColumn.Length = 255;
                                dbColumn.ColumnDescription = field.name;
                                dbColumn.DefaultValue = field.default_value;
                                dbColumn.IsNullable = true;
                            }
                            //dbColumn.DecimalDigits
                            data.AddColumn(table, dbColumn);
                        }
                    }
                }
                //如果频道名称改变则需要更改数据表名
                if (model.name != prevModel.name)
                {
                    string newTable = sysConfig.sysdatabaseprefix + DTKeys.TABLE_CHANNEL_ARTICLE + model.name;
                    data.RenameTable(table, newTable);
                }

                #region 编辑对应的导航==================
                if (siteNavParentId > 0)
                {
                    new DAL.navigation().Update("channel_" + prevModel.name, siteNavParentId, "channel_" + model.name, model.title, Utils.ObjToInt(model.sort_id));
                }
                new DAL.navigation().Update( "channel_" + prevModel.name + "_list", "channel_" + model.name + "_list"); //内容管理
                new DAL.navigation().Update("channel_" + prevModel.name + "_category", "channel_" + model.name + "_category"); //栏目类别

                //规格导航菜单处理
                if (model.is_spec > 0 && prevModel.is_spec == 0)
                {
                    //如开启规格而以前关闭的需新增菜单
                    new DAL.navigation().Add( "channel_" + model.name, "channel_" + model.name + "_spec", "规格管理", "article/spec_list.aspx", 102, model.id, "Show,View,Add,Edit,Delete");
                }
                else if (model.is_spec == 0 && prevModel.is_spec > 0)
                {
                    //如关闭规格而以前开启需删除菜单
                    data.Delete<Entitys.dt_navigation>(x => x.name == "channel_" + prevModel.name + "_spec");
                }
                else if (model.is_spec > 0)
                {
                    //如都是开启状态则修改菜单
                    new DAL.navigation().Update("channel_" + prevModel.name + "_spec", "channel_" + model.name + "_spec");
                }

                //评论导航菜单处理
                if (model.is_comment > 0 && prevModel.is_comment == 0)
                {
                    //如开启评论而以前关闭的需新增菜单
                    new DAL.navigation().Add( "channel_" + model.name, "channel_" + model.name + "_comment", "评论管理", "article/comment_list.aspx", 103, model.id, "Show,View,Add,Edit,Delete");
                }
                else if (model.is_comment == 0 && prevModel.is_comment > 0)
                {
                    //如关闭评论而以前开启需删除菜单
                    data.Delete<Entitys.dt_navigation>(x => x.name == "channel_" + prevModel.name + "_comment");
                }
                else if (model.is_comment > 0)
                {
                    //如都是开启状态则修改菜单
                    new DAL.navigation().Update( "channel_" + prevModel.name + "_comment", "channel_" + model.name + "_comment");
                }
                #endregion

                data.CommitTran();
            }
            catch(Exception ex)
            {
                data.RollbackTran();
                return false;
            }
            return true;

        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int id)
        {
            //取得频道的名称
            string channelName = GetChannelName(id);
            if (string.IsNullOrEmpty(channelName))
            {
                return false;
            }

            try
            {
                data.BeginTran();
                //取得要删除的所有导航ID
                List<int> navIds = new DAL.navigation().GetIds("channel_" + channelName);
                List<int> navIdList = new List<int>();
                foreach (int nid in navIds)
                {
                    navIdList.Add(nid);
                }

                //删除导航菜单表
                data.Delete<Entitys.dt_navigation>(x => navIdList.Contains(x.id));

                //删除扩展字段表
                data.Delete<Entitys.dt_site_channel_field>(x => x.channel_id == id);

                //删除频道数据表
                data.DropTable(sysConfig.sysdatabaseprefix + DTKeys.TABLE_CHANNEL_ARTICLE + channelName);

                //删除频道表
                data.Delete<Entitys.dt_site_channel>(x => x.id == id);

                data.CommitTran();
            }
            catch (Exception ex)
            {
                data.RollbackTran();
                return false;
            }
            return true;
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Entitys.dt_site_channel GetModel(int id)
        {
            Entitys.dt_site_channel model = data.Get<Entitys.dt_site_channel>(id);

            List<Entitys.dt_site_channel_field> fields = data.List<Entitys.dt_site_channel_field>(x => x.channel_id == model.id);
            if (fields != null)
            {
                if (fields.Count > 0)
                {
                    model.channel_fields = new List<Entitys.dt_site_channel_field>();
                    model.channel_fields.AddRange(fields);
                }
            }
            return model;
        }

        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public List<Entitys.dt_site_channel> GetList(int top, string strWhere, string filedOrder)
        {
            return data.List<Entitys.dt_site_channel>(top, strWhere, filedOrder);
        }

        /// <summary>
        /// 获得查询分页数据
        /// </summary>
        public List<Entitys.dt_site_channel> GetList(int pageSize, int pageIndex, string strWhere, string filedOrder, out int recordCount)
        {
            return data.List<Entitys.dt_site_channel>(pageSize, pageIndex, strWhere, filedOrder, out recordCount);
        }
        #endregion

        #region 扩展方法================================
        /// <summary>
        /// 查询频道名称是否存在
        /// </summary>
        public bool Exists(string name)
        {
            //与站点目录下的一级文件夹是否同名
            if (DirPathExists(sysConfig.webpath, name))
            {
                return true;
            }
            //与站点aspx目录下的一级文件夹是否同名
            if (DirPathExists(sysConfig.webpath + "/" + DTKeys.DIRECTORY_REWRITE_ASPX + "/", name))
            {
                return true;
            }
            //与存在的频道名称是否同名
            if (data.Exists<Entitys.dt_site_channel>(x=>x.name==name))
            {
                return true;
            }
            return false;
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Entitys.dt_site_channel GetModel(string channel_name)
        {
            return data.Get<Entitys.dt_site_channel>(x => x.name == channel_name);
        }

        /// <summary>
        /// 返回数据总数
        /// </summary>
        public int GetCount(Expression<Func<Entitys.dt_site_channel, bool>> whereExpression)
        {
            return data.Count<Entitys.dt_site_channel>(whereExpression);
        }


        /// <summary>
        /// 返回频道名称
        /// </summary>
        public string GetChannelName(int id)
        {
            Dictionary<int, string> dic = GetListAll();
            if (dic.ContainsKey(id))
            {
                return dic[id];
            }
            return string.Empty;
        }

        /// <summary>
        /// 返回频道ID
        /// </summary>
        public int GetChannelId(string name)
        {
            Dictionary<int, string> dic = GetListAll();
            foreach (KeyValuePair<int, string> kvp in dic)
            {
                if (kvp.Value.Equals(name))
                {
                    return kvp.Key;
                }
            }
            return 0;
        }

        /// <summary>
        /// 保存排序
        /// </summary>
        public bool UpdateSort(int id, int sort_id)
        {
            //取得频道的名称
            string channel_name = GetChannelName(id);
            if (channel_name == string.Empty)
            {
                return false;
            }
            if (new BLL.navigation().UpdateField(x => new Entitys.dt_navigation { sort_id=sort_id },x=>x.name == "channel_" + channel_name))
            {
                data.UpdateColumns<Entitys.dt_site_channel>(x => new Entitys.dt_site_channel { sort_id = sort_id }, x => x.id == id);
                return true;
            }
            return false;
        }

        /// <summary>
        /// 从缓存中取出所有频道字典
        /// </summary>
        public Dictionary<int, string> GetListAll()
        {
            Dictionary<int, string> dic = CacheHelper.Get<Dictionary<int, string>>(DTKeys.CACHE_SITE_CHANNEL_LIST);//从缓存取出
            //如果缓存已过期则从数据库里面取出
            if (dic == null)
            {
                dic = new Dictionary<int, string>();
                List<Entitys.dt_site_channel> list = data.List<Entitys.dt_site_channel>(string.Empty);
                if (list.Count > 0)
                {
                    foreach (Entitys.dt_site_channel c in list)
                    {
                        dic.Add(c.id, c.name);
                    }
                    CacheHelper.Insert(DTKeys.CACHE_SITE_CHANNEL_LIST, dic, 10);//重新写入缓存
                }
            }
            return dic;
        }
        #endregion

        #region 私有方法===============================
        /// <summary>
        /// 检查生成目录名与指定路径下的一级目录是否同名
        /// </summary>
        /// <param name="dirPath">指定的路径</param>
        /// <param name="build_path">生成目录名</param>
        /// <returns>bool</returns>
        private bool DirPathExists(string dirPath, string build_path)
        {
            DirectoryInfo dirInfo = new DirectoryInfo(Utils.GetMapPath(dirPath));
            foreach (DirectoryInfo dir in dirInfo.GetDirectories())
            {
                if (build_path.ToLower() == dir.Name.ToLower())
                {
                    return true;
                }
            }
            return false;
        }
        #endregion
    }
}